package com.ruoyi.reim.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.reim.domain.WorkflowReimDetail;
import com.ruoyi.reim.service.WorkflowReimDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 报销审批明细Controller
 *
 * @author ruoyi
 * @date 2021-07-16
 */
@RestController
@RequestMapping("/workflow/detail")
public class WorkflowReimDetailController extends BaseController
{
    @Autowired
    private WorkflowReimDetailService workflowReimDetailService;

    /**
     * 查询报销审批明细列表
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkflowReimDetail workflowReimDetail)
    {
        startPage();
        List<WorkflowReimDetail> list = workflowReimDetailService.selectWorkflowReimDetailList(workflowReimDetail);
        return getDataTable(list);
    }

    /**
     * 导出报销审批明细列表
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:export')")
    @Log(title = "报销审批明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WorkflowReimDetail workflowReimDetail)
    {
        List<WorkflowReimDetail> list = workflowReimDetailService.selectWorkflowReimDetailList(workflowReimDetail);
        ExcelUtil<WorkflowReimDetail> util = new ExcelUtil<WorkflowReimDetail>(WorkflowReimDetail.class);
        return util.exportExcel(list, "detail");
    }

    /**
     * 获取报销审批明细详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(workflowReimDetailService.selectWorkflowReimDetailById(id));
    }

    /**
     * 新增报销审批明细
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:add')")
    @Log(title = "报销审批明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkflowReimDetail workflowReimDetail)
    {
        return toAjax(workflowReimDetailService.insertWorkflowReimDetail(workflowReimDetail));
    }

    /**
     * 修改报销审批明细
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:edit')")
    @Log(title = "报销审批明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkflowReimDetail workflowReimDetail)
    {
        return toAjax(workflowReimDetailService.updateWorkflowReimDetail(workflowReimDetail));
    }

    /**
     * 删除报销审批明细
     */
    //@PreAuthorize("@ss.hasPermi('system:detail:remove')")
    @Log(title = "报销审批明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(workflowReimDetailService.deleteWorkflowReimDetailByIds(ids));
    }
}
